package com.supor.aiot.mine.ui.setting;


import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;

import com.android.baseconfig.common.utils.SystemUtils;
import com.supor.aiot.common.app.Constants;
import com.supor.aiot.common.app.SuporApplication;
import com.supor.aiot.common.base.BaseMVVMActivity;
import com.supor.aiot.common.base.NoViewModel;
import com.supor.aiot.common.ui.activity.WebActivity;
import com.supor.aiot.mine.R;
import com.supor.aiot.mine.databinding.ActivityAboutBinding;
import com.supor.aiot.mine.ui.activity.DebugSettingActivity;

public class AboutActivity extends BaseMVVMActivity<NoViewModel, ActivityAboutBinding> {

    private static final int TYPE = 1;

    @Override
    protected int resourceId() {
        return R.layout.activity_about;
    }

    @Override
    protected void initView() {
        super.initView();
        bindingView.toolbar.setIvLeftOnClickListener(v -> finish());
        bindingView.toolbar.setTvLeftOnClickListener(v -> finish());

        bindingView.tvVersion.setText(getString(R.string.version_prefix) + SystemUtils.getVerName(SuporApplication.getInstance()));
        bindingView.rlJumpToSupor.setOnClickListener(v -> {
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putInt(Constants.Key.param_type, TYPE);
            bundle.putString(Constants.Key.param_url, getString(R.string.about_supor_url));
            bundle.putString(Constants.Key.param_title, getString(R.string.supor));
            intent.putExtras(bundle);
            intent.setClass(this, WebActivity.class);
            startActivity(intent);
        });

        bindingView.ivLogo.setOnClickListener(v -> continuousClick());
    }

    /**
     * 点击次数
     */
    final static int COUNTS = 7;
    /**
     * 规定有效时间
     */
    final static long DURATION = 1500;
    long[] mHits = new long[COUNTS];

    private void continuousClick() {
        //每次点击时，数组向前移动一位
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        //为数组最后一位赋值
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
            //重新初始化数组
            mHits = new long[COUNTS];
            //执行逻辑
            // AuthnHelper.setDebugMode(true);
            // AppNetDelegate.setLogger(true);
            // Logc.setLogLevel(Logc.LogLevel.LEVEL_VERBOSE);
            // Logc.i("debug mode is open now!!!");
            // ToastUtils.getInstance().showCustomToast("Debug Mode");
            startActivity(new Intent(this, DebugSettingActivity.class));
        }
    }
}